﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;


    /// <summary>
    /// 数据库访问接口

    /// </summary>
    public interface IDBAccess
    {
        /// <summary>
        /// 打开数据库连接

        /// </summary>
        void OpenConnection();

        /// <summary>
        /// 关闭数据库连接

        /// </summary>
        void CloseConnection();

        /// <summary>
        /// 连接测试
        /// </summary>
        /// <returns>true: 成功</returns>
        bool TestDBConnection();

        /// <summary>
        /// 执行返回影响的行数

        /// </summary>
        /// <param name="commndText">命令文本</param>
        /// <param name="type">命令类别</param>
        /// <param name="paraList">命令参数</param>
        /// <returns>影响的行数</returns>
        int ExecuteNonQuery(string commndText, CommandType type, IDbDataParameter[] paraList);

        /// <summary>
        /// 执行返回数据记录集

        /// </summary>
        /// <param name="commndText">命令文本</param>
        /// <param name="type">命令类别</param>
        /// <param name="paraList">命令参数</param>
        /// <returns>数据记录集</returns>
        DataSet ExecuteDataSet(string commndText, CommandType type, IDbDataParameter[] paraList);

        /// <summary>
        /// 执行返回数据表

        /// </summary>
        /// <param name="commndText">命令文本</param>
        /// <param name="type">命令类别</param>
        /// <param name="paraList">命令参数</param>
        /// <returns>数据记录集</returns>
        DataTable ExecuteDataTable(string commndText, CommandType type, IDbDataParameter[] paraList);

        /// <summary>
        /// 执行返回首行首列
        /// </summary>
        /// <param name="commndText">命令文本</param>
        /// <param name="type">命令类别</param>
        /// <param name="paraList">命令参数</param>
        /// <returns>首行首列</returns>
        object ExecuteScalar(string commndText, CommandType type, IDbDataParameter[] paraList);

        /// <summary>
        /// 执行返回数据读取器

        /// </summary>
        /// <param name="commndText">命令文本</param>
        /// <param name="type">命令类别</param>
        /// <param name="paraList">命令参数</param>
        /// <returns>数据读取器</returns>
        IDataReader ExecuteDataRead(string commndText, CommandType type, IDbDataParameter[] paraList);

        /// <summary>
        /// 查询分页的数据

        /// </summary>
        /// <param name="pageBeginIndex">开始索引</param>
        /// <param name="pageSize">每一页显示的行数</param>
        /// <param name="commandType">命令类型</param>
        /// <param name="commandText">命令文本</param>
        /// <param name="dsTableName">数据表名称</param>
        /// <param name="paraList">命令参数</param>
        /// <returns></returns>
        DataSet ExecuteDataSet(int pageBeginIndex, int pageSize, CommandType commandType, string commandText, string dsTableName, System.Data.SqlClient.SqlParameter[] paraList);

        /// <summary>
        /// 一次性执行多条语句

        /// </summary>
        /// <param name="sqlComms">语句的集合</param>
        /// <returns>true ：成功</returns>
        bool ExecuteMultipleCmd(List<string> sqlComms);

        /// <summary>
        /// 创建参数
        /// </summary>
        /// <typeparam name="T">参数类型(继承 IDbDataParameter)</typeparam>
        /// <param name="names">参数名称的集合</param>
        /// <param name="types">参数类型的集合</param>
        /// <param name="values">参数值的集合</param>
        /// <returns>参数类型的数组</returns>
        IDbDataParameter[] CreateDBParameter(DBType type, string[] names, DbType[] types, object[] values);

    }

